package com.lyr.h2db;

import com.lyr.h2db.dao.UserRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * @author liyiruo
 * @Description
 * @Date 2024/8/15 下午2:40
 */
@SpringBootApplication
public class H2DBApp {

    public static void main(String[] args) {
        SpringApplication.run(H2DBApp.class,args);
        System.out.println("ok");
    }

    @Bean
    public CommandLineRunner demo(UserRepository userRepository) {
        return (args) -> {
            // 添加一些数据
            userRepository.addUser("John Doe");
            userRepository.addUser("Jane Doe");
            // 查询用户总数
            int userCount = userRepository.countUsers();
            System.out.println("Total users: " + userCount);
        };
    }
}
